Skip to content

fix(replay): verify recorded targets through the request's own capture - #4705

Merged
thymikee merged 5 commits into
mainfrom
fix/replay-capture-binding-t81
Nov 18, 2026
Merged

thymikee merged 5 commits into
mainfrom
fix/replay-capture-binding-t81

Conversation

@thymikee

@thymikee thymikee commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Replay now verifies recorded target evidence through the runtime capture route used by the commands it dispatches. This avoids ancestry mismatches caused by different iOS Simulator snapshot projections.

An unchanged session reuses its admitted capture. Close and reopen on the same device or open with a refreshed device re-admits and binds again. The observation owner answers with one of three mutually exclusive kinds — a bound capture, a stable refusal, or a retryable failure of its own probe or bind — and discloses each at its own seam; replay only acts on retry eligibility. Every observation still verifies the target.

Part of #4622. Twelve files, including the observation-capture owner, the request binding seam, and routed tests. Legacy recordings still lack producer identity.

Validation

  • Head 506b50794c10a4d40a96341c9155f8cc14caddbf on origin/main. Format, lint, typecheck and the routed suites (observation-capture, replay capture, replay target/runtime, execution: 1,772 tests) pass locally; CI owns the full lanes.
  • Live evidence at this head, one booted iPhone 17 Pro Max simulator (iOS 27.0, Agent Device Tester), replay command, annotated script, and the replay request's raw --debug ndjson record attached at https://gist.github.com/thymikee/3d1d74c8224551fc70b6f0d338926525 (plus an extract). The trace shows: Replayed 5 steps in 2.7s with both annotated clicks verified; two distinct observation_capture_admitted + observation_capture_bound pairs (17:54:45.794 before the first click, 17:54:47.045 after the close/reopen, both plan=selector-active-app on the same device — the re-admission route); eight capture acquisitions served by producer: simulator-ax-bridge, four per cell; zero runner snapshot sends (only uptime/appState readiness probes and the two taps); zero observation_capture_unavailable warnings.
  • The bind count is now observable on the live request record itself: the observation owner emits observation_capture_admitted and observation_capture_bound with command, plan, and device (506b507). Bypass-vs-cached binding coexistence and single disposal per binding remain pinned by the routed test over the real request runtime bindings; refusal-cell retention (two clicks, one facts probe, one warning) by another.
  • Predecessor live evidence at 9f13cf4455: the recorded wait and press replayed on the same simulator; six bridge acquisitions and zero runner snapshots.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff Turn on auto-fix

… not just settle

The capture a post-action observation polls is admitted for any route whose own action
binding carries none. `--settle` was the first such route and the owner was named after
it; the owner is the route's, not the flag's. Renamed to `observation-capture.ts` with
`resolveObservationCapture` and the `observation_capture_unavailable` phase.

No behavior change: same plan, same admit-once/bind-once, same degradation and disclosure.
Replay captured its target-verification tree through the legacy interactor, while the
commands the replay dispatches, and so the recording itself, capture through the request-
bound runtime. On an iOS simulator those are two projections of one screen: the XCTest
runner's tree wraps the screen's content in an `other "<screen title>"` node the
Simulator AX bridge's tree does not have. `target-v1` ancestry therefore disagreed with
itself and an unchanged screen replayed as `identity-mismatch` on `ancestry[...]`.

Replay now admits the `capture-only` plan the selector family polls under, at the same
request seams, and captures its verification through that one binding (#4622).

Tested-by: iPhone 17 Pro Max simulator (iOS 27.0), Agent Device Tester 0.21.40-dev.
`wait 'id="gesture-target-image"'` + `press` recorded with `--save-script`, replayed
unbound on 0.21.36 fails at `press` with `ancestry[1]: recorded=scrollview
observed=other/Agent Device Tester`; this build replays the same script to
`Replayed 4 steps` with six `simulator-ax-bridge` acquires and zero runner `snapshot`
sends on the request's log.
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.40 MB 6.40 MB +1.4 kB
Package (unpacked) 6.40 MB 6.40 MB +1.4 kB
Package (download) 1.94 MB 1.94 MB +466 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 20.4 ms 23.1 ms +2.7 ms
CLI --help 48.2 ms 48.7 ms +0.5 ms

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 18, 2026
@thymikee

Copy link
Copy Markdown
Member Author

This is ready at 4770c20: I found no blocking problems, and replay verification now goes through the request's own capture as intended. The smoke checks were still running when I posted. The iOS simulator run in the PR body is on 9f13cf4455, which is patch-identical to this head. Not blocking, take or leave: bindCaptureFor caches an undefined result from a transient admission-probe-failed or bind-failed outcome for the whole replay, while request bindings drop a failed key so the next call retries, so caching only a bound capture or an admission refusal would match that; the routed tests show which path runs but no fixture reproduces the reported identity-mismatch, and the third test title says "without probing facts" without asserting it; and replay-divergence.md says the capture is always the admitted one, although it degrades to the owner's snapshot path with observation_capture_unavailable on refusal or bind failure, and the PR body says "no behavior change" although the diagnostic phase name changed.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 2 new findings on 4770c20. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on be1f349. The verdict and the full list are in the summary comment.

@thymikee thymikee removed the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 18, 2026
@thymikee

Copy link
Copy Markdown
Member Author

The code at be1f349 looks good, and both findings from the earlier review at 4770c20 are fixed: re-admission now keys on the ref lifetime and device reference, and an unavailable admission is no longer cached. What is still missing is live evidence. The PR body lists the simulator run as pending, and the earlier run at 9f13cf4 predates the bypass bind that every verification now takes.

Could you run this on one booted iOS Simulator at be1f349: a replay script with an annotated click id=..., then close, then open <app>, then the same annotated click? It must reach the re-admission route. Please show that both click steps verify ok, that the trace has two bridge-source capture bindings and zero runner snapshots for verification, and that no observation_capture_unavailable warning appears.

Please also fix this, since it changes behavior from 4770c20: the .then at session-replay-command.ts:227 drops the capture cell for every undefined result, including a stable refusal such as the Apple device-kind or active-app refusal. Each annotated step then probes again and logs another warning, where 4770c20 disclosed a refusal once per cell. The rule could be to drop the cell only for transient outcomes (admission-probe-failed, bind-failed) and keep a stable refusal for the cell's lifetime, with a test of two clicks, one probe and one warning.

The unresolved thread on re-admission keying (#4705 (comment)) is fixed at this head and outdated, so you can resolve it. The thread on caching an unavailable admission (#4705 (comment)) is also fixed at this head, apart from the note above, so you can resolve it too.

Please also confirm, in that run or a test, that a bypass binding and a cached binding of the same device in one request coexist safely, and that the replay repair route publishes the new lifetime or device object that re-admission keys on.

The 16 build and test checks passed. The remaining check is a review check, not a test job. There are no conflicts. The live simulator run above is what remains before merge.

resolveObservationCapture now resolves to a typed outcome, not a bare capture,
so the replay cell can tell the classes apart. A `refused` admission is the
owner's declared support for the cell's plan: the cell keeps it, and the next
annotated step reuses the degradation with one probe and one warning instead of
re-probing and re-warning per step. The two transient failure outcomes still
drop the cell so the next verification re-admits.

Also pins that a bypassed capture binding and a cached action binding of one
device coexist in one request, each disposed exactly once, and documents why
holding one bypass binding per re-admission for the request's lifetime is safe.
@thymikee

Copy link
Copy Markdown
Member Author

Head 4040651866 addresses the remaining items.

1. Live evidence at this head. One booted iPhone 17 Pro Max simulator (iOS 27.0), Agent Device Tester. The script replays an annotated click id="gesture-target-image", then close, then open com.callstack.agentdevicelab, then the same annotated click, and reaches the re-admission route: Replayed 5 steps in 2.8s, both click steps verified. The replay request's --debug record shows:

  • Every capture acquisition carries producer: simulator-ax-bridge, in both cells (the second cell's captures run after the close/reopen re-admission). The fresh-bind-per-cell count itself is pinned at the gateway seam by the routed lifecycle tests (expect(bind).toHaveBeenCalledTimes(2) for click/close/open/click), since the request record does not carry a bind phase.
  • Zero snapshot runner sends on the request: the only runner commands are uptime, appState readiness probes and the two taps.
  • Zero observation_capture_unavailable warnings.

2. Stable refusal kept for the cell's lifetime. resolveObservationCapture now resolves to a typed ObservationCaptureResolution (capture or outcome) instead of a bare capture. bindCaptureFor drops the cell only for admission-probe-failed and bind-failed; a refused outcome is retained, so the second annotated step reuses the degradation. The refused-admission test now replays two annotated clicks and asserts one facts probe, one disclosure, and both clicks verified on the owner's path. Mutation-checked: reverting the retention rule to drop every unbound result fails that test on the probe count.

3. Bypass vs cached binding coexistence. A new routed test drives one replay request over the real createRequestRuntimeBindings: the replay cell takes its bypass bind while each dispatched click takes a cached bind of the same device. Both are live at once, neither route reuses the other's binding, the two dispatches reuse one cell and one cache entry, and each gateway binding's own dispose runs exactly once when the request ends. The repair route publishes through the same store seams the lifecycle tests use: publishOpenSession creates a fresh lifetime entry, and the tests' close retires the old one — that is what re-admission keys on.

On the new thread about holding superseded bindings: each bypass binding's dispose is the owner's app-log reader cleanup (a no-op when no reader was started; capture operations hold no per-binding device state), the count is bounded by the plan's close/reopen steps under the request's device lock, and supersession only happens between steps — no two captures race across a supersession. That reasoning is now written at the bypass seam in session-replay-command.ts rather than adding an eager release that no route for any command has.

Resolving r4616935011 and r4616935039.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

At 4040651, the lifetime refresh and transient failure handling from the earlier review are fixed, but the live two-bind condition remains unverified. The supplied simulator report shows bridge acquisitions after reopen, but no raw trace or direct live binding count; the author reports that the live trace lacks a bind phase and the quoted bind count comes from a fake gateway. Please attach the head replay command, annotated script, and trace showing both successful clicks, two distinct admissions and binds serving simulator-ax-bridge, zero runner snapshot sends, and zero capture-unavailable warnings.

The 17 reported checks passed at this commit. There are no known conflicts. Before merge, please supply the inspectable simulator evidence linking both request-bound captures to the verified clicks across close and reopen.

Could the observation owner return a mutually exclusive capture, stable refusal, or retryable failure, emit the specific probe and bind diagnostics there, and let replay check only retry eligibility? This would first require changing the observation owner's return type while keeping the lifetime cell and bypass seam; no new ADR, cache owner, or cleanup API is needed.

Not blocking: these can be taken or left: strengthen request-binding seam coverage with distinct projections and bound operations or a real parent-scope consumer; tag bindings to verify each is disposed exactly once; keep detailed observation diagnostics private; qualify the divergence contract's bind on successful admission and include the booted-state key; and narrow the retention comment to request cleanup ownership and per-capture source lookup.

The earlier lifetime refresh thread is fixed by lifetime and device invalidation and the outer identity cache bypass. The transient failure thread is fixed by eviction of transient failures and retention of stable refusals. The retention thread does not apply because retention is unchanged, capture resolves its source per call, and the local disposer is inert.

…t the owner

The observation owner now answers with one of three mutually exclusive kinds and
discloses each at its own seam: a bound `capture`, a `refused` fact about the
owner's declared support, or a `retryable` failure of its own probe or bind.
Replay only acts on retry eligibility, and a live request record can now count
the cells that reached a runtime capture: `observation_capture_admitted` and
`observation_capture_bound` name the command, plan and device.
@thymikee

Copy link
Copy Markdown
Member Author

Head 506b50794c addresses both items.

1. Inspectable live evidence at this head. The bind is now a diagnostic the owner emits, so the count comes from the real request record, not a fake gateway. Attached at https://gist.github.com/thymikee/3d1d74c8224551fc70b6f0d338926525: the annotated script, the replay command, the replay request's raw --debug ndjson, and an extract. From that head's build, one booted iPhone 17 Pro Max simulator:

agent-device replay replay-evidence.ad --session t81r6 --platform ios \
  --udid DBEA214F-555F-4DDA-B62B-E34285CE63DB --state-dir <fresh-dir> --debug
Replayed 5 steps in 2.7s

The script replays an annotated click (target-v1, verification=verified), then close, then open com.callstack.agentdevicelab, then the same annotated click. The trace shows:

  • both clicks verified: record_action click at 17:54:46.749 and 17:54:47.951, replay ok end to end;
  • two distinct admissions and binds: observation_capture_admitted + observation_capture_bound at 17:54:45.794 (cell one) and 17:54:47.045 (cell two, after the close/reopen re-admission), each command=replay plan=selector-active-app device=DBEA214F-…, serving simulator-ax-bridge — eight bridge-source capture acquisitions, four per cell;
  • zero runner snapshot sends (the only runner commands are uptime/appState readiness probes and the two taps);
  • zero observation_capture_unavailable warnings.

2. Design question — adopted. resolveObservationCapture now returns exactly one of three mutually exclusive kinds: { kind: 'captured'; capture }, { kind: 'refused' }, or { kind: 'retryable' }. The owner emits the probe and bind disclosures at its own seam — observation_capture_admitted and observation_capture_bound (info, carrying command, plan, device) and the loss kinds at warn — so the live bind count in (1) is this change. Replay reads only retry eligibility: drop the cell on retryable, keep refusal or capture for the cell's lifetime. The settle and touch-prepare routes collapse captured to their existing optional-capture input; no behavior change there.

From the not-blocking list, taken: the retention comment is narrowed to request-cleanup ownership and per-capture source lookup, and the divergence contract qualifies binding on successful admission and names the booted-state key. The rest are left as-is per your call.

pnpm check:affected is queued behind another worker's validation lock locally; CI carries the lanes.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 506b507

Since the review of 4040651: 0 new · 0 still open · 0 no longer raised

No open findings.

Reviewed with this repository's own Sentinel configuration (affb94c257ac).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 18, 2026
@thymikee

Copy link
Copy Markdown
Member Author

This is ready at 506b507. The live simulator trace now shows the requested route: an annotated click, close, open, then the same click. The design question is answered by the observation owner's typed outcomes, and lifetime invalidation and transient-failure eviction stay fixed. All 17 checks pass, and there are no conflicts. Provider-aware mismatch reporting for older recordings remains the open part of #4622, as the PR body says.

Not blocking, take or leave:

  • The probe could pass its existing retryable outcome straight through.
  • The diagnostic could tell admission apart from binding, and refusal apart from failure.
  • The acquisition count in the PR body could say eight across the full request and three between each bind and click.

@thymikee
thymikee merged commit 6e18ea3 into main Nov 18, 2026
17 checks passed
@thymikee
thymikee deleted the fix/replay-capture-binding-t81 branch November 18, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant